package com.bss.controller;

import com.bss.pojo.Company;
import com.bss.service.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 袁飞
 * @company 中原工学院
 * @create 2020-03-14-19:49
 */
@RestController
@RequestMapping("/bss/company")
public class CompanyController {
    @Autowired
    CompanyService CompanyService;
    @RequestMapping("find")
    public Company getCompany(@RequestParam("id") Integer id){
        return CompanyService.findCompanyById(id);
    }
    @RequestMapping("addOrUpd")
    public void addOrUpd(Company Company){
        System.out.println(Company);
        if ((Company.getCompanyId()!= null)){
            CompanyService.updateCompany(Company);
        }else {
            CompanyService.addCompany(Company);
        }
    }
    @RequestMapping("del")
    public void delCompany(@RequestParam("id") Integer id){
        CompanyService.deleteCompanyById(id);
    }
    @RequestMapping("getAll")
    public PageInfo<Company> getAll(Integer pageNum){
        if(pageNum==null){
            pageNum=1;
        }
        PageHelper.startPage(pageNum,5);
        List<Company> CompanyList = CompanyService.findAll();
        PageInfo<Company> CompanyPageInfo = new PageInfo<Company>(CompanyList);
        return CompanyPageInfo;
    }
    @RequestMapping("getCompanysBycompanyType")
    public List<Company> getProductsByOrderType(Integer companyType){
        return CompanyService.findCompanysByCompanyType(companyType);
    }
    @RequestMapping("query")
    public  PageInfo<Company> query(String companyName,String companyAddr){
        System.out.println(companyName);
        System.out.println(companyAddr);
        PageHelper.startPage(1,5);
        List<Company> CompanyList = CompanyService.findCompany(companyName,companyAddr);
        PageInfo<Company> CompanyPageInfo = new PageInfo<Company>(CompanyList);
        return CompanyPageInfo;
    }
}
